import cv2
import numpy as np

def select_erode(dst):

    if dst.shape[0] * dst.shape[1] > 1080 * 1920:
        kernel = np.ones((3, 3), np.uint8)
        dst = cv2.erode(dst, kernel)
    
        return dst
    else: 
        return dst

def get_line(img_name, input_path, temp_path):    

    img = cv2.imread(img_name)         
    height, width, n = img.shape       
    print(height*width) 
    gray0 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)          
    img2 = np.zeros((height,width), dtype='uint8')        
  
    gray1 = cv2.addWeighted(gray0, -1, img2, 0, 255, 0)    
    # cv2.imshow("img0", gray1)                         

    gray1 = cv2.GaussianBlur(gray1, (155, 155), 0)      
    dst = cv2.addWeighted(gray0, 1, gray1, 1, 0)  


    dst = select_erode(dst)
    # cv2.imshow("sketch_img", dst)
    # cv2.waitKey(0)             

    if img_name.endswith(".jpg"):
        save_name = temp_path + str(img_name).replace('.jpg', '_line.jpg').replace(input_path, '')
    if img_name.endswith(".png"):
        save_name = temp_path + str(img_name).replace('.png', '_line.jpg').replace(input_path, '')

    cv2.imwrite(save_name, dst)

